interface CheckCondition {
  format: string[];
  size: number
}
type ErrorType = 'format' | 'size' | null
interface CheckResult {
  passed: boolean,
  error: ErrorType
}
export function beforeUploadCheck (file: File, condition: CheckCondition):CheckResult {
  const { format, size } = condition
  const isValidFormat = format ? format.includes(file.type) : true
  const isValidSize = size ? file.size / 1024 / 1024 < size : true
  let error:ErrorType = null
  if (!isValidFormat) {
    error = 'format'
  }
  if (!isValidSize) {
    error = 'size'
  }
  return {
    passed: isValidSize && isValidFormat,
    error
  }
}
